<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
      .imgs img {
        width: 80px;
        border: 2px solid white;
      }
      .imgs .active {
        border-color: purple;
      }
      .box {
        position: relative;
      }
      .wrap {
        position: absolute;
        left: 420px;
        top: 0;
        width: 200px;
        height: 200px;
        overflow: hidden;
        transform-origin: 0 0;
        transform: scale(2.5);
      }
      .wrap img {
        position: absolute;
        top: 0;
        left: 0;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="box" ref="box">
        <img :src="imgs[i]" @mousemove="move" style="width: 420px" alt="" />
        <div class="imgs">
          <img
            v-for="(url,index) in imgs"
            :src="url"
            @click="i=index"
            :class="{active:index==i}"
            alt=""
          />
        </div>
        <!-- 大图 -->
        <div class="wrap">
          <img
            :src="imgs[i]"
            :style="{width: '420px',left:pos.left,top:pos.top}"
            alt=""
          />
        </div>
      </div>
    </div>
  </body>
  <script>
    let app = Vue.createApp({
      data() {
        return {
          imgs: [
            "http://bfs.biyao.com/group2/M00/25/41/CghiFmUjncKAWi9iABjB-wFJJss625_800x800.jpg",
            "http://bfs.biyao.com/group2/M00/74/48/CghiFmL-5teACsFIAB8d5X_83SI816_800x800.jpg",
            "http://bfs.biyao.com/group2/M00/74/29/CghkFmL-5tqADMn7AB81pETgGgg629_800x800.jpg",
            "http://bfs.biyao.com/group2/M00/74/48/CghiFmL-5t2AXXncABit7bGMJQw778_800x800.jpg",
            "http://bfs.biyao.com/group2/M00/74/48/CghiFmL-5uCAZJ2eAByUosANuLQ523_800x800.jpg",
          ],
          i: 0,
          pos: {
            left: 0,
            top: 0,
          },
        };
      },
      methods: {
        move(e) {
          // 鼠标到图片左上角的距离
          let x = e.clientX - this.$refs.box.offsetLeft;
          let y = e.clientY - this.$refs.box.offsetTop;
          // 限制边界
          if (x < 100) x = 100;
          if (x > 320) x = 320;
          if (y < 100) y = 100;
          if (y > 320) y = 320;
          this.pos = {
            left: -x + 100 + "px",
            top: -y + 100 + "px",
          };
        },
      },
    });
    app = app.mount("#app");
  </script>
</html>
